#include <iostream>
#include <cmath>
#include <unordered_map>
#include <string>

bool baz(int num) {
    if (num < 2) {
        return false;
    }
    for (int i = 2; i <= static_cast<int>(std::sqrt(num)) + 1; i++) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

void nearest_prime(std::string word1, std::string word2, std::string word3) {
    std::unordered_map<std::string, std::string> n = {
        {"zero", "0"}, {"one", "1"}, {"two", "2"}, {"three", "3"}, {"four", "4"},
        {"five", "5"}, {"six", "6"}, {"seven", "7"}, {"eight", "8"}, {"nine", "9"}
    };
    std::string num_str = n[word1] + n[word2] + n[word3];
    
    if (!std::all_of(num_str.begin(), num_str.end(), ::isdigit) || num_str.length() != 3) {
        std::cout << "Wrong input" << std::endl;
        return;
    }
    
    int num = std::stoi(num_str);
    int l = num - 1;
    int h = num + 1;
    
    while (!baz(l)) {
        l--;
    }
    while (!baz(h)) {
        h++;
    }
    
    if (num - l <= h - num) {
        std::cout << l << std::endl;
    } else {
        std::cout << h << std::endl;
    }
}

int main() {
    std::string words[3];
    std::cout << "Введите три слова на английском языке(числа от 0 до 10): ";
    for (int i = 0; i < 3; i++) {
        std::cin >> words[i];
    }
    nearest_prime(words[0], words[1], words[2]);
    return 0;
}